package com.vercon.commonmirror.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.LinearLayout
import com.vercon.commonmirror.R

/**
 * Created by YZC on 2019/9/3
 */
class BodyPicker : LinearLayout {

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        bindView()
    }

    lateinit var iv_body1: ImageView
    lateinit var iv_body2: ImageView
    lateinit var iv_body3: ImageView
    lateinit var iv_body4: ImageView
    lateinit var iv_body5: ImageView
    lateinit var iv_body6: ImageView
    var picker = mutableListOf<ImageView>()

    fun bindView() {
        LayoutInflater.from(context).inflate(R.layout.widget_smarthome_body_picker, this)
        iv_body1 = findViewById(R.id.iv_body1)
        iv_body2 = findViewById(R.id.iv_body2)
        iv_body3 = findViewById(R.id.iv_body3)
        iv_body4 = findViewById(R.id.iv_body4)
        iv_body5 = findViewById(R.id.iv_body5)
        iv_body6 = findViewById(R.id.iv_body6)
        picker.add(iv_body1)
        picker.add(iv_body2)
        picker.add(iv_body3)
        picker.add(iv_body4)
        picker.add(iv_body5)
        picker.add(iv_body6)

    }

    private var preSelect = -1
    fun select(cur: Int){
        if(preSelect in 0..5) picker.get(preSelect).isSelected = false
        preSelect = cur
        if(preSelect in 0..5){
            picker.get(cur).isSelected = true
        }
    }

    fun curSelected() = preSelect
}